<?php
class MauvppsController extends AppController {

	var $name = 'Mauvpps';
    var $layout='trangchu';
	function index() {
		$this->Mauvpp->recursive = 0;
		$this->set('mauvpps', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid mauvpp', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('mauvpp', $this->Mauvpp->read(null, $id));
	}

	function add() {
	   $this->layout='trangchu';
       		if (!empty($this->data)) {
			$this->Mauvpp->create();
			if ($this->Mauvpp->save($this->data)) {
				$this->Session->setFlash(__('The mauvpp has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The mauvpp could not be saved. Please, try again.', true));
			}
		}
		$quis = $this->Mauvpp->Qui->find('list');
        $this->Mauvpp->Canbo->displayField="macb";
		$canbos = $this->Mauvpp->Canbo->find('list');
        $this->Mauvpp->Donvi->displayField="tendonvi";
        $donvis = $this->Mauvpp->Donvi->find('list');
		$this->set(compact('quis', 'canbos', 'donvis'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid mauvpp', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Mauvpp->save($this->data)) {
				$this->Session->setFlash(__('The mauvpp has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The mauvpp could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Mauvpp->read(null, $id);
		}
        $this->Mauvpp->Donvi->displayField="tendonvi";
        $donvis = $this->Mauvpp->Donvi->find('list');
		$quis = $this->Mauvpp->Qui->find('list');
		$canbos = $this->Mauvpp->Canbo->find('list');
		$this->set(compact('quis', 'canbos','donvis'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for mauvpp', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Mauvpp->delete($id)) {
			$this->Session->setFlash(__('Mauvpp deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Mauvpp was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
